Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wrap-ansi

Package Overview
Dependencies
Maintainers
3
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrap-ansi

Wordwrap a string with ANSI escape codes

  • 7.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is wrap-ansi?

The wrap-ansi npm package is used to wrap words to a specified column width without breaking ANSI escape codes. This is particularly useful for formatting command-line output that includes color or other special styles.

What are wrap-ansi's main functionalities?

Word wrapping

This feature allows you to wrap a string to a specified width. In the code sample, the input string is wrapped so that each line does not exceed 20 characters.

const wrapAnsi = require('wrap-ansi');
const input = 'The quick brown fox jumps over the lazy dog';
const output = wrapAnsi(input, 20);
console.log(output);

Respecting ANSI escape codes

This feature ensures that ANSI escape codes are not broken when the text is wrapped. The code sample demonstrates wrapping text that includes ANSI escape codes for red text.

const wrapAnsi = require('wrap-ansi');
const input = '\u001B[31mThe quick brown fox\u001B[39m jumps over the lazy dog';
const output = wrapAnsi(input, 20);
console.log(output);

Hard wrapping

This feature allows for hard wrapping, which ensures that line breaks are inserted at exactly the specified column, even if it means breaking a word. The code sample shows how to use the 'hard' option to enforce strict column width.

const wrapAnsi = require('wrap-ansi');
const input = 'The quick brown \nfox jumps over the lazy dog';
const output = wrapAnsi(input, 20, { hard: true });
console.log(output);

Other packages similar to wrap-ansi

Keywords

FAQs

Package last updated on 22 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc